import {
	ENUM_MEDIA_TYPE
} from "../../static/enum";
export default class MediaModel {
	constructor(imageUrl, imageType = ENUM_MEDIA_TYPE.IMAGE.value, thumbUrl) {
		this.setImageUrl(imageUrl, imageType, thumbUrl);
	}
	setImageUrl(imageUrl, imageType, thumbUrl) {
		this.imageUrl = imageUrl;
		this.imageType = imageType;
		this.thumbUrl = thumbUrl;
		if (!thumbUrl) {
			initThumbUrl.call(this)
		}
	}
}

function initThumbUrl() {
	switch (this.imageType) {
		case ENUM_MEDIA_TYPE.IMAGE.value:
			initImageThumbUrl.call(this);
			break;
		case ENUM_MEDIA_TYPE.VIDEO.value:
			initVideoThumbUrl.call(this);
			break;
	}
}

function initImageThumbUrl() {
	if (this.imageUrl.indexOf('?x-oss-process') != -1) {
		this.thumbUrl = this.imageUrl;
	} else {
		this.thumbUrl = `${this.imageUrl}?x-oss-process=image/resize,p_50,m_fill,w_100`;
	}
}

function initVideoThumbUrl() {
	if (this.imageUrl.indexOf('?x-oss-process') != -1) {
		this.thumbUrl = this.imageUrl;
	} else {
		this.thumbUrl = `${this.imageUrl}?x-oss-process=video/snapshot,t_0,f_jpg`;
	}
}